home *** CD-ROM | disk | FTP | other *** search
- Path: web.cae.ca!usenet
- From: fraserh@cae.ca (Fraser Hutchinson)
- Newsgroups: comp.lang.c++
- Subject: Re: Union equivelant in C++
- Date: 4 Mar 1996 18:10:09 GMT
- Organization: CAE Electronics Ltd.
- Message-ID: <4hfbm1$t53@web.cae.ca>
- References: <3130A7A2.404D@bath.ac.uk>
- NNTP-Posting-Host: pch63.cae.ca
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In article <3130A7A2.404D@bath.ac.uk>, ma2rct@bath.ac.uk says...
- >
- >I need to store a data structure where there is more than one
- >choice for what is stored.
- >
- >Effectively a structure of unions.
- >
- >Is there anything better than a union that is C++ specific.
-
- Yes, class inheritance and polymorphism.
-
- i.e, create a base class for the union, and derive a class for each data
- type you want to handle. If you provide properly designed virtual
- methods in the base class, you will achieve the result you desire.
-
- Regards,
-
-
- Fraser
-
-
-